-
-
Notifications
You must be signed in to change notification settings - Fork 213
fix: HTTP client exception not handled properly resulting in incorrectly formatted error #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: HTTP client exception not handled properly resulting in incorrectly formatted error #1021
Conversation
|
🚀 Thanks for opening this pull request! |
|
Can you please run CI? |
|
@mbfakourii done |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1021 +/- ##
==========================================
+ Coverage 43.72% 43.98% +0.26%
==========================================
Files 61 61
Lines 3465 3469 +4
==========================================
+ Hits 1515 1526 +11
+ Misses 1950 1943 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I will reformat the title to use the proper commit message syntax. |
|
I rephrased the PR title; not sure whether it accurately describes the issue, could you please review? |
|
I think it's better. |
|
There is still an open review discussion and the changelog entry + version bump is missing in the PR. See other PRs on how they are done. Then we can go ahead and merge. |
📝 WalkthroughWalkthroughAdded an Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SDK as Parse SDK
participant HTTP as http.Client
participant Builder as buildParseResponseWithException
Client->>SDK: perform request
SDK->>HTTP: send request
alt http.ClientException thrown
HTTP-->>SDK: throws ClientException
SDK->>Builder: buildParseResponseWithException(ClientException)
Builder-->>SDK: ParseResponse{ error: ParseError(message, exception) }
else DioException thrown
HTTP-->>SDK: throws DioException
SDK->>Builder: buildParseResponseWithException(DioException)
Builder-->>SDK: ParseResponse{ error: ParseError(parsedMessage, parsedCode, exception) }
else other Exception
HTTP-->>SDK: throws Exception
SDK->>Builder: buildParseResponseWithException(Exception)
Builder-->>SDK: ParseResponse{ error: ParseError(message, exception) }
end
SDK-->>Client: return ParseResponse (error)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
I thought changelog and version bump should be maintained on release instead of PR merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/dart/lib/parse_server_sdk.dart (1)
12-12: Narrow http import to avoid potential symbol clashes with dioGiven this is the root library for many
partfiles and you already importpackage:dio/dio.dart, bringing in all ofpackage:http/http.dartrisks name clashes (e.g.,Response) in any part that uses unqualified types.Since the only thing needed here is
ClientExceptionforbuildParseResponseWithException, consider narrowing the import:-import 'package:http/http.dart'; +import 'package:http/http.dart' show ClientException;This keeps the namespace clean while still enabling the new exception handling.
Please double‑check that no other symbols from
httpare used anywhere in the parts of this library before applying this change.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/dart/lib/parse_server_sdk.dart(1 hunks)packages/dart/lib/src/objects/response/parse_exception_response.dart(1 hunks)
🔇 Additional comments (1)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)
25-29: ClientException handling looks correct and aligns with existing patternsThe new
ClientExceptionbranch cleanly maps http client errors into aParseError, consistent with the generic fallback (no explicit error code, message taken from the exception) and separate from the richerDioExceptionhandling above.Functionally this should resolve the issue where
ClientException.toString()was previously exposed.Please confirm:
- That you have a test covering a thrown
ClientExceptionand asserting the resultingParseResponse.error.message.- That no additional metadata (e.g., a specific error code) is needed for
ClientExceptionbeyond what the generic fallback already provided.
|
@2shrestha22 each PR merge triggers a release. |
updated |
|
Fixed the CI issues in #1046, should all pass now |
3d06272
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)
26-30: ClientException mapping fixes the bug; consider a more specific error codeHandling
ClientExceptionexplicitly and surfacingexception.messagedirectly addresses the original issue and keeps the original exception attached, which is good.If you want to distinguish network/client errors from generic ones, you could optionally set a dedicated
ParseErrorcode here (for example a “connection failed” constant, if available in this SDK) instead of relying on the defaultotherCause. That would make it easier for callers to branch on network vs. server errors.Example (only if you decide to specialize the code):
- if (exception is ClientException) { - return ParseResponse( - error: ParseError(message: exception.message, exception: exception), - ); - } + if (exception is ClientException) { + return ParseResponse( + error: ParseError( + message: exception.message, + exception: exception, + // Consider using a dedicated connection/network error code here. + ), + ); + }This is optional and can be deferred.
packages/dart/test/src/objects/response/parse_exception_response_test.dart (1)
1-72: Good coverage of exception-mapping behavior; consider one more small caseThese tests nicely pin down the behaviors for:
- DioException with JSON payload (message + string code),
- DioException with non-JSON body (status message/code fallback),
- http ClientException,
- generic Exception,
and they verify that the original exception object is preserved in all cases. This is exactly what the production code is doing.
If you want one more safety net, you could add a variant of the first test where
codeis an integer ('code': 123) to guard against future regressions in the numeric-path handling, but that’s strictly a nice-to-have.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/dart/lib/src/objects/response/parse_exception_response.dart(2 hunks)packages/dart/test/src/objects/response/parse_exception_response_test.dart(1 hunks)
🔇 Additional comments (1)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)
14-23: DioException errorcodeparsing is correct and improves robustnessUsing
codeStringplusint.tryParsebefore falling back tostatusCodegives you a clean numeric error code whether the server sends"123"or123, and preserves the existing fallback toParseError.otherCausewhen nothing is available. The logic is sound and aligns with the new tests.
|
Interesting, were there still some failing tests? |
|
|
Got it, is this ready for merge now? |
|
Yes ready to merge |
Pull Request
Issue
Closes: #1022
Approach
Tasks
Summary by CodeRabbit
Bug Fixes
Refactor
Tests
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.